#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import models
from django.core.validators import MaxValueValidator
import os
import sys
import django

sys.path.append(r"web")
sys.path.append(r"algorithm")
sys.path.append(r"cta")

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adam3.settings')
django.setup()


class Optimize2AccountLog(models.Model):
    """
    优化2--账户日志表
    """

    # 主键
    id_ = models.AutoField(primary_key=True)

    # 日期
    date_ = models.DateField(null=True, db_index=True, blank=True)

    # 账户名字
    account_name = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # 持有期货的数量
    hold_commodity_future_number = models.IntegerField(validators=[MaxValueValidator(2147483647)], null=True,
                                                       blank=True)

    # 期货资产（保证金+收益或损失）
    commodity_future_assets = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 资金资产
    capital_assets = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 总资产
    total_assets = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 总开仓手续费
    total_open_commission = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 总平仓手续费
    total_close_commission = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 5日均线
    ma5 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 10日均线
    ma10 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 20日均线
    ma20 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 60日均线
    ma60 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 120日均线
    ma120 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 250日均线
    ma250 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 5日bias
    bias5 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 10日bias
    bias10 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 20日bias
    bias20 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 60日bias
    bias60 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 120日bias
    bias120 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    # 250日bias
    bias250 = models.DecimalField(max_digits=32, decimal_places=3, null=True, blank=True)

    class Meta:
        managed = True
        db_table = 'optimize2_account_log'
        verbose_name = '优化2--账户日志表'
        verbose_name_plural = verbose_name
        # 单列索引
        # indexes = [
        #     models.Index(fields=['code']),
        #     models.Index(fields=['k_line_period_type']),
        #     models.Index(fields=['begin_time']),
        #     models.Index(fields=['end_time']),
        #     models.Index(fields=['name']),
        # ]
        # 联合索引
        # index_together = [('code', 'buy_date', 'sell_date')]
